package com.admin.business.portalWebsite.venusJobVacancy;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 招聘信息表
 * @create: 2023-11-21 14:18:29
 **/
@Service("venusJobVacancyService")
@Slf4j
public class VenusJobVacancyService{

    @Resource
    VenusJobVacancyDao venusJobVacancyDao;

    /**
     * 添加,获取job_id数据
     *
     * @param cdoRequest - job_id:
     *                   - org_id:公司ID
     *                   - pro_id:项目ID
     *                   - post_id:岗位ID
     *                   - job_number:招聘人数
     *                   - job_age_start:招聘最小年龄
     *                   - job_age_end:招聘最大年龄
     *                   - job_gender:招聘性别
     *                   - job_experience:工作经验
     *                   - job_compensation_start:薪资开始
     *                   - job_compensation_end:薪资结束
     *                   - job_nature:岗位性质
     *                   - job_education:学历
     *                   - job_welfare:公司福利
     *                   - job_requirements:任职要求
     *                   - job_responsibility:岗位职责
     *                   - job_status:状态（1上线、2下线）
     *                   - sys_user:创建人
     *                   - create_time:创建时间
     *                   - job_view_num:浏览量
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return addVenusJobVacancy(CDO cdoRequest) {
        venusJobVacancyDao.addVenusJobVacancy(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("job_id")) {
            cdoResult.set("job_id", cdoRequest.get("job_id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据job_id，更新数据
     *
     * @param cdoRequest - job_id:
     *                   - org_id:公司ID
     *                   - pro_id:项目ID
     *                   - post_id:岗位ID
     *                   - job_number:招聘人数
     *                   - job_age_start:招聘最小年龄
     *                   - job_age_end:招聘最大年龄
     *                   - job_gender:招聘性别
     *                   - job_experience:工作经验
     *                   - job_compensation_start:薪资开始
     *                   - job_compensation_end:薪资结束
     *                   - job_nature:岗位性质
     *                   - job_education:学历
     *                   - job_welfare:公司福利
     *                   - job_requirements:任职要求
     *                   - job_responsibility:岗位职责
     *                   - job_status:状态（1上线、2下线）
     *                   - sys_user:创建人
     *                   - create_time:创建时间
     *                   - job_view_num:浏览量
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return updateVenusJobVacancyById(CDO cdoRequest) {
        venusJobVacancyDao.updateVenusJobVacancyById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据job_id，删除数据
     *
     * @param cdoRequest - job_id:
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return deleteVenusJobVacancyById(CDO cdoRequest){
        int count = venusJobVacancyDao.deleteVenusJobVacancyById(cdoRequest.getLong("job_id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return deleteVenusJobVacancy(CDO cdoRequest) {
        int count = venusJobVacancyDao.deleteVenusJobVacancy(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取数据
     *
     * @param cdoRequest - job_id:
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusJobVacancyById(CDO cdoRequest) {
        CDO cdoMapperResult = venusJobVacancyDao.getVenusJobVacancyById(cdoRequest.getLong("job_id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusJobVacancyListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusJobVacancyDao.getVenusJobVacancyListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusJobVacancyDao.getVenusJobVacancyCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取数据列表
     *
     * @param cdoRequest - job_id:
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusJobVacancyListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusJobVacancyDao.getVenusJobVacancyListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusJobVacancyDao.getVenusJobVacancyCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
